do
    -- use pin 1 as the input pulse width counter
    local pin, pulse1, du, now, trig = 3, 0, 0, tmr.now, gpio.trig
    gpio.mode(pin, gpio.INT)
    local function pin1cb(level)
        local pulse2 = now()
        print(level, pulse2 - pulse1)
        pulse1 = pulse2
        trig(pin, level == gpio.HIGH and "down" or "up")
    end
    trig(pin, "down", pin1cb)
end